#include "GowildResponseSceneListCmd.h"

GowildResponseSceneListCmd::GowildResponseSceneListCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::GowildProtocol;
    this->m_functionCode = FunctionCode;
}

Package GowildResponseSceneListCmd::toPackage()
{
    Package package;

    QVariantMap jsonData;
    jsonData.insert("type","RESPONSE_SCENE");

    QVariantList dataList;
    QList<int> sceneIdList = m_sceneHash.keys();
    for(int i=0; i<sceneIdList.size(); i++)
    {
        QVariantMap data;
        int sceneId = sceneIdList.at(i);
        Gowild::SceneStruct scene = m_sceneHash.value(sceneId);
        QString sceneName = scene.room() + scene.name();
        data.insert("id",QString::number(sceneId,10));
        data.insert("name",sceneName);
        dataList.append(data);
    }
    jsonData.insert("data",dataList);

    QJson::Serializer serializer;
    QByteArray body = serializer.serialize(jsonData, NULL);

    package.setBody(body);
    package.setFunction(FunctionCode);

    return package;

}

void GowildResponseSceneListCmd::unPackage(Package package)
{
    Q_UNUSED(package);
}
QHash<int, Gowild::SceneStruct> GowildResponseSceneListCmd::sceneHash() const
{
    return m_sceneHash;
}

void GowildResponseSceneListCmd::setSceneHash(const QHash<int, Gowild::SceneStruct> &sceneHash)
{
    m_sceneHash = sceneHash;
}

